#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
    class Solution {
    public:
        ListNode* detectCycle(ListNode* head) {
            ListNode* slow = head, * fast = head;
            while (fast != nullptr && fast->next != nullptr) {
                slow = slow->next;
                fast = fast->next->next;
                if (fast == slow) {
                    while (slow != head) {
                        slow = slow->next;
                        head = head->next;
                    }
                    return slow;
                }
            }
            return nullptr;
        }


    };